const mapObj=document.querySelector('.map')
let results = [
    ['','','','','',  '','','','','', '','','','','',],
    ['','','','','',  '','','','','', '','','','','',],
    ['','','','','',  '','','','','',  '','','','','',],
    ['','','','','',  '','','','','',  '','','','','',],
    ['','','','','',  '','','','','',  '','','','','',],

    ['','','','','',  '','','','','',  '','','','','',],
    ['','','','','',  '','','','','',  '','','','','',],
    ['','','','','',  '','','','','',  '','','','','',],
    ['','','','','',  '','','','','',  '','','','','',],
    ['','','','','',  '','','','','',  '','','','','',],

    ['','','','','',  '','','','','',  '','','','','',],
    ['','','','','',  '','','','','',  '','','','','',],
    ['','','','','',  '','','','','',  '','','','','',],
    ['','','','','',  '','','','','',  '','','','','',],
    ['','','','','',  '','','','','',  '','','','','',],
]

for(let row=0;row<15;row++){
let rowObj=document.createElement('div')
rowObj.className='row'
for(let col=0;col<15;col++){
let colObj=document.createElement('div')
colObj.className='col'
rowObj.appendChild(colObj)
colObj.setAttribute('row',row)
colObj.setAttribute('col',col)

}
mapObj.appendChild(rowObj)
}
function random(min=0,max=1){
    return Math.floor(Math.random()*(max-min+1)+min)
}
let targetObj=null
let colorArr=['black','white']
let colorIndex=random()
mapObj.onclick=function(evt){
    let e=evt || window.event
    let target = e.target || e.srcElement
    if (target.className.includes('col '||'col ')) return
    if(target.className.includes('col')){
    target.className=`col ${colorArr[colorIndex]}`
    let rowI=target.getAttribute('row')
    let colI=target.getAttribute('col')
    results[rowI][colI]=colorArr[colorIndex]
    colorIndex=Number(!colorIndex)
    targetObj = target
}
}
let btnObj=document.querySelector('button')
btnObj.style.marginLeft='30px'
btnObj.style.width=btnObj.style.height='100px'
btnObj.onclick=function(){
    targetObj.className = 'col'
    colorIndex=Number(!colorIndex)
}